//
//  SelectImageViewCell.swift
//  Employee
//
//  Created by Saxon on 2018/3/28.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import UIKit
import Photos

class SelectImageViewCell: UITableViewCell {

    
    static let identifier = "SelectImageViewCell.identifier"
    
    fileprivate var imageSelectV: ImageSelectV!
    fileprivate var tipLabel: UILabel!
    
    var assets: [PHAsset] = [] {
        didSet {
            imageSelectV.assets = assets
        }
    }
    var titleName: String = "" {
        didSet {
            imageSelectV.titleName = titleName
        }
    }
    var addPhotoClosure: VoidClosure? {
        didSet {
            guard let closure = addPhotoClosure else { return }
            imageSelectV.addPhotoClosure = closure
        }
    }
    
    var deleteClosure: ( (Int) -> () )? {
        didSet {
            guard let closure = deleteClosure else { return }
            imageSelectV.deleteClosure = closure
        }
    }
    
    var cellDidClickAction: ( (Int) -> () )? {
        didSet {
            imageSelectV.cellDidClickAction = cellDidClickAction
        }
    }
    var typeName: String!
    
    lazy var mainView:UIView = {
        let mainView = UIView()
        mainView.backgroundColor = UIColor.white
        mainView.layer.cornerRadius = 4
        mainView.clipsToBounds = true
        self.addSubview(mainView)
        
        mainView.snp.makeConstraints { (make) in
            make.left.equalTo(10)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(UIScreen.width-20)
        }
        
        return mainView
    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.backgroundColor = UIColor.clear;
        
        imageSelectV = ImageSelectV()
        imageSelectV.titleName = titleName
        mainView.addSubview(imageSelectV)
        
        let height = (UIScreen.width - 80) / 4
        imageSelectV.snp.makeConstraints { (make) in
            make.top.equalTo(10)
            make.left.right.equalTo(0)
            make.height.equalTo(height + 30 + 15)
        }
        
        tipLabel = UILabel()
        mainView.addSubview(tipLabel)
        tipLabel.font = GlobalConfig.system15Font
        tipLabel.textColor = GlobalConfig.TextLightColor
        tipLabel.text = "最多可以添加4个附件"
        tipLabel.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.top.equalTo(imageSelectV.snp.bottom)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
